// import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
// import render from '@dfeidao/atom-web/render/render';
import set from '@dfeidao/atom-web/local/set';
// import storage_put from '@dfeidao/atom-web/storage/put';

import javadsd from '@dfeidao/atom-web/msg/javadsd';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import { refsystemid } from './config';
import render from '@dfeidao/atom-web/render/render';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import P01 from './P01';
import P03 from './P03';
import P04 from './P04';
import P05 from './P05';
interface B {
	docDataStore: {
		master: {
			dataArray: [{
				no: string;
				group_number: string
				group_name: string;
				formid: string;
				formname: string;
				grid_1: {
					dataArray: [
						{
							no: string;
							group_number: string;
							group_name: string;
							formid: string;
							formname: string;
						}
					]
				}
			}]
		};
	};
}
export default async function a001(fd: IFeidaoAiBrowserComponent) {

	const prid = fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-id="user"]').getAttribute('prid');
	set(fd, 'productid', prid);

	const res = await nodejs<{ dataArray: Array<{}> }>('tenant-function/zj-000001/s001', { filter: { productid: prid } });// 端点下拉框初始化的值
	render(fd, res.dataArray, P04, "P04", "inner");

	const res1 = await nodejs<{ dataArray1: Array<{}>, page_no: number, page_size: number; count: number; }>('tenant-function/zj-000001/s002', { filter: { tenant_name: '', productid: prid }, page_size: 10, page_no: 1 });// 用户列表初始化查询
	render(fd, res1.dataArray1, P01, "P01", "inner");
	res1.page_no = 1;
	res1.page_size = 10;

	// const name1 = fd.data.node.querySelectorAll<HTMLDivElement>('[xz]');
	// name1[0].classList.add('w-bg-themef');
	// const tenantid = name1[0].getAttribute('data-feidao-id');
	// set(fd, 'tenantid', tenantid);

	const select1 = fd.data.node.querySelector<HTMLSelectElement>('[select]');
	const index = select1.options.selectedIndex;
	const client_type1 = select1.options[index].value;// client_point_id 客户端编号
	const condition = {
		param: {
			productid: prid,
			client_type: client_type1
		}
	};
	set(fd, 'client_type', client_type1);
	const ret = await javadsd('12', '12', 'smart_securitydsd0000010', condition) as B;
	// debugger;
	const array = new Array();
	ret.docDataStore.master.dataArray.forEach((i) => {
		i.group_number = i.group_number ? i.group_number : 'weifenzhu';
		if (i.grid_1.dataArray.length > 0) {
			i.grid_1.dataArray.forEach((j) => {
				j.no = i.group_number;
				array.push(j);
			});
		}
		i.formid = i.group_number;
		i.formname = i.group_name;
		delete i.grid_1;
		i.no = '';
		// if (!i.formid) {
		// 	i.formid = JSON.stringify(idex);
		// }
		array.push(i);
	});
	// set(fd, 'all_data', array);
	// console.log(ret.docDataStore.master.dataArray);
	render(fd, JSON.stringify(array), P05, 'P05', 'inner');
	// console.log(array);
	if (res1.count) {
		render(fd, res1, P03, "P03", "inner");
	} else {
		render(fd, '', '', "P03", "inner");
	}
}
